package com.intermancer.predictor.lifecycle;

import com.intermancer.predictor.inject.InjectStrategy;
import com.intermancer.predictor.store.StoreEntry;
import com.intermancer.predictor.store.StoreEntryDAO;

public class InjectCommand extends LifecycleCommandBase {
	
	private InjectStrategy injectStrategy;
	private StoreEntryDAO storeEntryDAO;
	
	public InjectCommand() {
		// Nothing.
	}
	
	public InjectCommand(InjectStrategy injectStrategy, StoreEntryDAO storeEntryDAO) {
		this.injectStrategy = injectStrategy;
		this.storeEntryDAO = storeEntryDAO;
	}

	@Override
	boolean innerExecute(LifecycleContext context) {
		for(StoreEntry storeEntry : context.getStoreEntries()) {
			StoreEntry storedEntry = injectStrategy.inject(storeEntry, storeEntryDAO);
			if((storedEntry != null) && (storedEntry.getIdentity() != null)) {
				context.addStoredEntry(storedEntry);
			}
		}
		return false;
	}

	public void setInjectStrategy(InjectStrategy injectStrategy) {
		this.injectStrategy = injectStrategy;
	}

	public void setStoreEntryDAO(StoreEntryDAO storeEntryDAO) {
		this.storeEntryDAO = storeEntryDAO;
	}

}
